﻿namespace LeadMaster.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Entity;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using LeadMaster.Models;
    using LeadMaster.DAL;
    using LeadMaster.ViewModels;

    public class ScheduleSectionsController : Controller
    {
        private DunsmoreContext db = new DunsmoreContext();

        //
        // GET: /ScheduleSections/

        public ActionResult Index()
        {
            return View(db.ScheduleSection.OrderByDescending(m => m.Category).ToList());
        }

        //
        // GET: /ScheduleSections/Details/5

        public ActionResult Details(int id = 0)
        {
            ScheduleSection schedulesections = db.ScheduleSection.Find(id);
            if (schedulesections == null)
            {
                return HttpNotFound();
            }
            return View(schedulesections);
        }

        //
        // GET: /ScheduleSections/Create

        public ActionResult Create()
        {
            ViewBag.SectionMergesID = new SelectList(db.SectionMerges.OrderBy(m => m.DisplayOrder), "Markup", "Description");

            return View();
        }

        //
        // POST: /ScheduleSections/Create

        [HttpPost]
        public ActionResult Create(ScheduleSection schedulesections)
        {
            if (ModelState.IsValid)
            {
                db.ScheduleSection.Add(schedulesections);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(schedulesections);
        }

        //
        // GET: /ScheduleSections/Edit/5

        public ActionResult Edit(int id = 0)
        {
            ViewModelScheduleSections viewModel = new ViewModelScheduleSections();
            viewModel.ScheduleSection = db.ScheduleSection.Find(id);
            viewModel.holdingSectionMerge = string.Empty;
            if (viewModel.ScheduleSection == null)
            {
                return HttpNotFound();
            }
            return View(viewModel);
        }

        //
        // POST: /ScheduleSections/Edit/5

        [HttpPost]
        public ActionResult Edit(ViewModelScheduleSections viewModel)
        {
            if (ModelState.IsValid)
            {
                db.Entry(viewModel.ScheduleSection).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(viewModel);
        }

        //
        // GET: /ScheduleSections/Delete/5

        public ActionResult Delete(int id = 0)
        {
            ScheduleSection schedulesections = db.ScheduleSection.Find(id);
            if (schedulesections == null)
            {
                return HttpNotFound();
            }
            return View(schedulesections);
        }

        //
        // POST: /ScheduleSections/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            ScheduleSection schedulesections = db.ScheduleSection.Find(id);
            db.ScheduleSection.Remove(schedulesections);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}